﻿using System;
using Navigant.Infrastructure.Cases;
using Navigant.Infrastructure.RepositoryFramework;
using Navigant.Infrastructure.DomainBase;
using System.Collections.Generic;

namespace Navigant.Model.Cases
{
    public static class CaseService
    {
        private static ICaseRepository repository;

        static CaseService()
        {
            CaseService.repository = CaseRepositoryFactory.GetCaseRepository();
        }

        public static Case GetCaseBy(Uri caseAddress)
        {
            Case caseItem = null;
            ICase foundCase = CaseService.repository.FindBy(caseAddress);
            if (foundCase != null)
            {
                caseItem = new Case(foundCase);
            }
            return caseItem;
        }

        /* Date : 09-Aug-08
         * Develper : Rajul Patel
         * Description : We can't search Case Site from its Guid without SPSite Id.
         * Method is added to find the site by its SPSite and Case Site (SPWeb) Id
         */
        public static ICase GetCaseBy(Guid siteCollectionKey, Guid caseKey)
        {
            Case caseItem = null;
            ICase foundCase = CaseService.repository.FindBy(siteCollectionKey, caseKey);
            if (foundCase != null)
            {
                caseItem = new Case(foundCase);
            }
            return caseItem;
        }
        
        public static IList<HtmlImageData> GetAllImages(ICase currentCase)
        {
            return CaseService.repository.FindAllImages(currentCase);
        }

        public static void SetSetting(ICase currentCase, string name, int numberValue)
        {
            CaseService.repository.SetSetting(currentCase, name, numberValue);
        }
    }
}
